package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.xcity.db.entity.ActivityRecord;
import com.xcity.db.entity.Player;
import com.xcity.game.player.cache.PlayerCacheService;

import naga.x.App;
import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;
import naga.x.util.TimeUtils;

@PomeloMessage(type = Message.Type.RESPONSE)
public class OneYuanActivityPrizeRecordResponse extends Response {
	
	private List<PrizeInfo> list = Collections.emptyList();
	
	public static class PrizeInfo {
		private int phase;
		private int round;
		private long playerId;
		private String playerName;
		private String playerIcon;
		private int playerLevel;
		private String time;
		public int getPhase() {
			return phase;
		}
		public void setPhase(int phase) {
			this.phase = phase;
		}
		public int getRound() {
			return round;
		}
		public void setRound(int round) {
			this.round = round;
		}
		public long getPlayerId() {
			return playerId;
		}
		public void setPlayerId(long playerId) {
			this.playerId = playerId;
		}
		public String getPlayerName() {
			return playerName;
		}
		public void setPlayerName(String playerName) {
			this.playerName = playerName;
		}
		public String getPlayerIcon() {
			return playerIcon;
		}
		public void setPlayerIcon(String playerIcon) {
			this.playerIcon = playerIcon;
		}
		public int getPlayerLevel() {
			return playerLevel;
		}
		public void setPlayerLevel(int playerLevel) {
			this.playerLevel = playerLevel;
		}
		public String getTime() {
			return time;
		}
		public void setTime(String time) {
			this.time = time;
		}
	}
	
	public OneYuanActivityPrizeRecordResponse(int serial, List<ActivityRecord> records) {
		super(serial);
		if (records.isEmpty()) {
			return;
		}
		PlayerCacheService as = App.getApp().getServiceManager().get(PlayerCacheService.class);
		list = new ArrayList<PrizeInfo>(records.size());
		for (int i = 0; i < records.size(); i++) {
			ActivityRecord ref = records.get(i);
			PrizeInfo info = new PrizeInfo();
			info.setPhase(ref.getPhase());
			info.setRound(ref.getRound());
			Player player = as.find(ref.getPlayerId());
			info.setPlayerId(player.getId());
			info.setPlayerName(player.getName());
			info.setPlayerIcon(player.getIcon());
			info.setPlayerLevel(player.getLevel());
			info.setTime(TimeUtils.format(ref.getTime()));
			list.add(info);
		}
	}

	public List<PrizeInfo> getList() {
		return list;
	}

	public void setList(List<PrizeInfo> list) {
		this.list = list;
	}
	
}
